package com.edfu.core.identitymgt.persistence.entity;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import com.edfu.core.institutemgt.persistence.entity.BatchEntity;

@Entity
@Table(name="userenrollment", uniqueConstraints=@UniqueConstraint(columnNames={"user_id" , "role_id", "batch_id"}))
public class UserEnrollmentEntity implements IIdentityMgtEntity {
	private long id;
	private UserEntity user;
	private RoleEntity role;
	private boolean deleted;
	private boolean suspended;
	private Date createdOn;
	private Date lastModifiedOn;
	private BatchEntity batch;
	private UserEnrollmentDataEntity enrollmentData;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	
	@ManyToOne
	@JoinColumn(name = "user_id", nullable = false)
	public UserEntity getUser() {
		return user;
	}
	public void setUser(UserEntity user) {
		this.user = user;
	}
	
	@ManyToOne
	@JoinColumn(name = "batch_id", nullable = false)
	public BatchEntity getBatch() {
		return batch;
	}
	public void setBatch(BatchEntity batch) {
		this.batch = batch;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "role_id", nullable = false)
	public RoleEntity getRole() {
		return role;
	}
	public void setRole(RoleEntity role) {
		this.role = role;
	}
	public boolean isDeleted() {
		return deleted;
	}
	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}
	public boolean isSuspended() {
		return suspended;
	}
	public void setSuspended(boolean suspended) {
		this.suspended = suspended;
	}
	public Date getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}
	public Date getLastModifiedOn() {
		return lastModifiedOn;
	}
	public void setLastModifiedOn(Date lastModifiedOn) {
		this.lastModifiedOn = lastModifiedOn;
	}
	
	@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "userenroldata_id")
	public UserEnrollmentDataEntity getEnrollmentData() {
		return enrollmentData;
	}
	public void setEnrollmentData(UserEnrollmentDataEntity enrollmentData) {
		this.enrollmentData = enrollmentData;
	}
	
	
}
